package org.projectname.service.admin.book;

import java.util.List;
import java.util.Map;

import org.hishenframework.core.data.jdbc.template.JdbcOperater;
import org.projectname.entity.book.BookPart;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 图书分类业务类
 * @author didi
 *
 */
@Service
@Transactional
public class BookPartService extends JdbcOperater<BookPart> {

	/**
	 * 删除
	 * 复写了父类方法
	 */
	public int delete(int id) {		
		String sql = "select count(*) from t_book where book_part_id = ?";
		long count = super.getJdbcTemplate().queryForLong(sql, id);
		//如果该分类下已有图书，则不不进行删除
		return count == 0 ? super.delete(id) : 0;
		
	}
	
	/**
	 * 类别列表
	 * @return
	 */
	public List<Map<String, Object>> list() {
		String sql = "select *, (select count(*) from t_book where book_part_id = t1.id) typeCount from t_book_part t1";
		return getJdbcTemplate().queryForList(sql);
	}
}
